-- Automation 4 K帧脚本
-- 对选中行加K值，值取字幕持续时间与K段数的商
-- 初版日期 20150127
-- 第三版日期 20150127

local tr = aegisub.gettext

script_name = tr("K帧脚本")
script_description = tr("对选中行加K值，值取字幕持续时间与K段数的商")
script_author = "Wandway"
script_version = "第三版"
script_last_update_time = '2015/10/27'

include("unicode.lua")


function SylSubtitle(subtitles, selected_lines, active_line)
	for z, i in ipairs(selected_lines) do
		local l = subtitles[i]	
		local newtext = ""
		for c in unicode.chars(l.text) do			
			newtext = newtext..string.format('{\\K%d}', (l.end_time - l.start_time)/string.len(l.text)/4)..c			
		end
		l.text = newtext
		subtitles[i] = l
	end
	aegisub.set_undo_point(script_name)
end

aegisub.register_macro(script_name, script_description, SylSubtitle)